package com.learn.actionplatfo.controller;

import com.learn.actionplatfo.bean.Good;
import com.learn.actionplatfo.service.GoodForUserService;
import com.learn.actionplatfo.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class GoodController {
    @Autowired
    GoodService goodService;
    @Autowired
    GoodForUserService goodForUserService;

    @RequestMapping("/getGoodList")
    public String getGoodList(Model model){
        model.addAttribute("GFUList",goodService.getAllGood());
        return "good";
    }

    @RequestMapping("/updateGood")
    public String updateGood(int newAttribute,int id,Model model){
        Good good = goodService.getGoodById(id);
        good.setGoodAttribute(newAttribute);
        goodService.updateGood(good);
        model.addAttribute("GFUList",goodForUserService.getMainPageList());
        return "main";
    }
}
